package pl.edu.agh.gronoMining.owlToGraphConverter;

import java.util.Properties;

public class Settings {

	private Properties properties = new Properties();
	
	public static final String INPUT_FILE_PROP_NAME = "inputFile";
	public static final String GSPAN_INPUT_FILE_PROP_NAME = "gSpanInputFile";
	public static final String GSPAN_OUTPUT_FILE_PROP_NAME = "gSpanOutputFile";
	public static final String OUTPUT_FILE_PROP_NAME = "outputFile";
	public static final String MINIMUM_FREQUENCIES = "minimumFrequencies";
	
	public Settings() {
		
	}
	
	public boolean parseSettings(String[] args) {
		boolean isInputFile = false;
		String inputFileName = "";
		for (String arg : args) {
			String[] argument = arg.split("=");
			if (("-"+INPUT_FILE_PROP_NAME).equals(argument[0])) {
				properties.setProperty(INPUT_FILE_PROP_NAME, argument[1]);
				inputFileName = argument[1];
				isInputFile = true;
			} else if (("-"+GSPAN_INPUT_FILE_PROP_NAME).equals(argument[0]) ||
					("-"+GSPAN_OUTPUT_FILE_PROP_NAME).equals(argument[0]) ||
					("-"+OUTPUT_FILE_PROP_NAME).equals(argument[0]) ||
					("-"+MINIMUM_FREQUENCIES).equals(argument[0])) {
				properties.setProperty(argument[0].substring(1, argument[0].length()), argument[1]);
			} else {
				return false;
			}
		}
		if (! properties.containsKey(GSPAN_INPUT_FILE_PROP_NAME))
			properties.setProperty(GSPAN_INPUT_FILE_PROP_NAME, inputFileName+".gSpan.in");
		if (! properties.containsKey(GSPAN_OUTPUT_FILE_PROP_NAME))
			properties.setProperty(GSPAN_OUTPUT_FILE_PROP_NAME, inputFileName+".gSpan.out");
		if (! properties.containsKey(OUTPUT_FILE_PROP_NAME))
			properties.setProperty(OUTPUT_FILE_PROP_NAME, inputFileName+".out");
		if (! properties.containsKey(MINIMUM_FREQUENCIES))
			properties.setProperty(MINIMUM_FREQUENCIES, "20%");
		return isInputFile;
	}
	
	public String getArgumentsInfo() {
		return "-"+INPUT_FILE_PROP_NAME+"=[input file name]\n-"+OUTPUT_FILE_PROP_NAME+"=[output file name]";		
	}
	
	public String getProperty(String propertyName) {
		return properties.getProperty(propertyName);
	}
}
